<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/jquery-3.5.1.min.js"></script>
</head>
<body>
        <div>评论</div>
        <div th:text="${comVos}"></div>
        <div>
            <input type="text" class="userid" th:value="${comVos.get(0).userId}" style="display: none">
            <input type="text" class="inputtj">
            <button type="submit" onclick="submit()">提交</button>
        </div>
        <div th:each="co:${comVos}">
            name：<span th:text="${co.username}" class="username"></span>
            评论：<span th:text="${co.comment}"></span>
            <span th:onclick="dz([[${co.comId}]],this)">点赞</span>
            <span th:text="${co.like}"></span>
        </div>
</body>
<script>
    function dz(comId,btn){
        alert(1111)
        var like = parseInt($(btn).next().text())+1
        $.ajax({
            url:"/comment/like",
            dataType:"json",
            type:"post",
            data:{"like":like,"comId":comId},
            success:(res)=>{
                location.reload()
            },error:(ree)=>{
                alert("错误")
            }
        })
    }
   function submit(){
       var comment = $(".inputtj").val()
       var username = $(".username").val()
       var userid = $(".userid").val()
       $.ajax({
           url:"/comment/insert",
           dataType:"json",
           type:"post",
           data:{"comment":comment,"username":username,"userId":userid},
           success:(res)=>{
               location.reload()
           },error:(ree)=>{
               alert("添加错误")
           }
       })
   }
</script>
</html>